<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

</body>
<script>
  function respone_use() {
    // return { token: '123' }
    return Promise.reject(new Error('失败了'))
  }
  function request() {
    return new Promise((resolve, reject) => {
      // resolve('123')
      // reject(new Error('失败了'))

      // 标准写法
      // resolve(new Promise((resolve2, reject2) => {
      //   resolve2('123')
      // }))
      // 简化写法
      // resolve(Promise.resolve('123'))

      // 标准写法,理解响应拦截器核心
      // resolve(new Promise((resolve2, reject2) => {
      //   reject2(new Error('失败了'))
      // }))
      // 简化写法
      // resolve(Promise.reject(new Error('失败了')))
      // resolve(respone_use())
    })
  }
  let p = request()
  p.then(data => {
    //成功回调
    console.log('data', data)
  }).catch(error => {
    //失败回调
    console.log('error', error)
  })
</script>

</html>
